package com.ruoyi.common.ums.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.ums.dao.YytUmsMemberCollectSpuMapper;
import com.ruoyi.common.ums.entity.YytUmsMemberCollectSpu;
import com.ruoyi.common.ums.service.YytUmsMemberCollectSpuService;
import org.springframework.stereotype.Service;

/**
 * 用户收藏商品Service类
 *
 * @author tanxingxian
 * @date 2021-12-22 15:53
 */
@Service
public class YytUmsMemberCollectSpuServiceImpl extends ServiceImpl<YytUmsMemberCollectSpuMapper, YytUmsMemberCollectSpu>
        implements YytUmsMemberCollectSpuService {

    /**
     * 收藏（取消收藏）商品
     */
    @Override
    public String collect(YytUmsMemberCollectSpu collectSpu) {
        LambdaQueryWrapper<YytUmsMemberCollectSpu> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(YytUmsMemberCollectSpu::getMemberId, collectSpu.getMemberId());
        wrapper.eq(YytUmsMemberCollectSpu::getSkuId, collectSpu.getSkuId());
        YytUmsMemberCollectSpu dbCollect = getOne(wrapper);
        if (null == dbCollect) {   // 收藏
            save(collectSpu);
            return "收藏成功";
        } else {    // 取消收藏
            remove(wrapper);
            return "取消收藏成功";
        }
    }
}
